home *** CD-ROM | disk | FTP | other *** search
/ Internet.Works 41 / Issue 41.iso / pc / PCSoftware / Netscape 6 Official Release / nim.xpi / bin / chrome / aim.jar / content / aim / aimHdrViewOverlay.js < prev    next >
Encoding:
JavaScript  |  2000-08-31  |  4.9 KB  |  154 lines

  1. /* This overlay JS file contains the JS necessary for integrating
  2.    AIM presence into the messenger msg header pane overlay (msgHdrViewOverlay).
  3.  
  4.    It allows us to dynamically modify the msg hdr view overlay to add 
  5.    presence indication for email addresses in that pane.
  6. */
  7.  
  8. /* we need to implement a data source observer on the buddy list so we
  9.    are notified when people are online or not 
  10. */ 
  11.  
  12.  
  13. // cache the properties we are interested in...
  14. var buddyStateString = RDF.GetResource("http://home.netscape.com/NC-rdf#BuddyStateString");
  15.  
  16. // cache the various aim services we are going to need in order to pull this off.
  17.  
  18. var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager);
  19. var aimABInfo = pIIMManager.QueryInterface(Components.interfaces.nsIAimABInfo);
  20. var aimBuddyInfo = pIIMManager.QueryInterface(Components.interfaces.nsIAimBuddy);
  21. var aimLocateManager = pIIMManager.QueryInterface(Components.interfaces.nsIAimLocateManager);
  22.  
  23. // This array of dom nodes is an array indexed by URI that keeps track of the
  24. // dom nodes in the msg header pane we care about...
  25. var domNodes = new Object();
  26.  
  27. var AimDataSourceObserver = 
  28. {
  29.   onAssert: function(datasource, source, property, target)
  30.   {
  31.     // onAssert is going to be called a lot, so make sure you try to kick out
  32.     // as early as possible to avoid any extra over head.....
  33.       if(source.EqualsNode(AimSession))
  34.       {
  35.           if(property.EqualsNode(SessionState))
  36.           {
  37.         var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  38.         // if we are going offline then be sure to clear the presence state for 
  39.         // all of the aim resources we are interested in.
  40.         if (state && state == "Offline")
  41.         {
  42.           for (i in domNodes)
  43.             domNodes[i].setAttribute("BuddyStateString", "Offline");
  44.         }
  45.       }
  46.     }
  47.     else if (property.EqualsNode(buddyStateString))
  48.     {
  49.       var targetString = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  50.       // dump("changing buddy state for" + source.Value + "with target: " + targetString + "\n");
  51.       var node = domNodes[source.Value];
  52.       //var node = domNodes[node];
  53.       if (node)
  54.         SetPresence(node, target);
  55.     }
  56.   },
  57.  
  58.   onUnassert: function(datasource, source, property, target)
  59.   {
  60.   },
  61.  
  62.   onChange: function(datasource, source, property, oldTarget, newTarget)
  63.   {
  64.     AimDataSourceObserver.onAssert(datasource, source, property, newTarget);
  65.   },
  66.  
  67.   onMove: function(datasource, oldSource, newSource, property, target)
  68.   {
  69.     AimDataSourceObserver.onAssert(datasource, newSource, property, target);
  70.   },
  71.  
  72.   beginUpdateBatch: function(datasource)
  73.   {
  74.   },
  75.  
  76.   endUpdateBatch: function(datasource)
  77.   {
  78.   }
  79. };
  80.  
  81. /* SetPresence updates the titled button image (node)
  82.    based on the property value of presence
  83. */
  84. function SetPresence(node, presence)
  85. {
  86.   if (node)
  87.   {
  88.    // if we have a node that corresponds to this URI, then we need to poke
  89.    // it....
  90.     var targetString = presence.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  91.     node.setAttribute("BuddyStateString", targetString);
  92.     // this silly align hack is because css isn't noticing the alignment
  93.     // attribute unless I set it to something...then set it back to what
  94.     // I really want...
  95.     node.setAttribute("align", "left");
  96.     node.setAttribute("align", "right");
  97.     node.setAttribute("max-height", "15px");
  98.   }
  99. }
  100.  
  101. /* Extract the AIM ID from the node and send an instant message
  102. */
  103. function SendIMFor (node)
  104. {
  105. //XXXjelwellXXX might need to change state from OnlineAway to Online
  106.   var target = AimDataSource.GetTarget(AimSession, SessionState, true);
  107.   var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  108.   if ("OnlineAway" == state)
  109.   {
  110.     if ( aimLocateManager ) {
  111.         aimLocateManager.SetUserInfoAwayMessage(null);
  112.     }
  113.   }
  114.  
  115.   if (node)
  116.   {
  117.     var screenName = node.getAttribute("IMScreenName");
  118.     if (screenName)
  119.     {
  120.       aimIMInvokeIMForm(screenName, null);
  121.     }
  122.     else
  123.       aimIMInvokeIMForm(null, null);
  124.   }
  125. }
  126.  
  127. function AddToBuddyListFor(node)
  128. {
  129. //XXXjelwellXXX might need to change state from OnlineAway to Online
  130.   if (node)
  131.   {
  132.     var screenName = node.getAttribute("IMScreenName");
  133.     openDialog("chrome://aim/content/BuddyAddBuddy.xul", "", "modal=yes,titlebar,chrome", null, null, screenName);
  134.   }
  135. }
  136.  
  137. /* OnLoadAimHdrViewOverlay --> called when the overlay is first loaded...
  138.    This is where we will register ourself as an observer on the AIM data source.
  139. */
  140.  
  141. function OnLoadAimHdrViewOverlay ()
  142. {
  143.   AimDataSource.AddObserver(AimDataSourceObserver);
  144. }
  145.  
  146. function OnUnLoadAimHdrViewOverlay ()
  147. {
  148.   AimDataSource.RemoveObserver(AimDataSourceObserver);
  149. }
  150.  
  151. // Install our load handler
  152. addEventListener("load", OnLoadAimHdrViewOverlay, false);
  153. addEventListener("unload", OnUnLoadAimHdrViewOverlay, false);
  154.